--------------------------------------------------------------------------------
      name:  <unnamed>
       log:  E:\Seagate Sync\VOL\Personal folder\Documents\Research\Past project
> s\cbld\Posted\121020 Website\Data analysis\cbld-analysis02-fig05.log
  log type:  text
 opened on:  21 Oct 2012, 15:41:51

. 
. 
. * ****************************************************************************
> ***
. * Fig. 5. Effect of voting threshold on winning coalition size by membership s
> ize
. * ****************************************************************************
> ***
. 
. * Programme:    cbld-analysis02-fig05.do
. * Project:              Council coalition building
. * Author:               Frank Haege, Department of Politics and Administration
> , University of Limerick
. * Contact:              frank.haege@ul.ie
. 
. * Description
. *************
. * This do-file generates a figure demonstrating the nonlinear relationship bet
> ween 
. * voting threshold and winning coalition size for different membership sizes. 
. * For each membership size, a panel shows how the predicted median curve and i
> nterquartile
. * range, the median winning coalition size based on the simulated data, and th
> e effective
. * voting threshold varies as a function of the formal voting threshold.
. 
. 
. * Set up Stata
. version 11

. clear all

. macro drop _all

. set linesize 80

. set more off

. 
. * Load data set
. use "Experiments\Experiment01\cbld-model-121020-exp01.dta", clear

. 
. 
. * Prepare data for non-linear quantile regression analysis in R
. ***************************************************************
. 
. * Generate consensus variable
. generate consensus = (noblock/nostates)*100

. label var consensus "Size of Winning Coalition (Percent)"

. 
. * Generate variables standardized between 0 and 1       
. generate normconsensus = ((consensus - 50) * 2) / 100

. label var normconsensus "nrmlzd: Size of Winning Coalition"

. generate normvthresh = ((vthresh - 50) * 2) / 100

. label var normvthresh "nrmlzd: Voting Threshold"

. 
. * Generate variable taking the logarithm of the standardized variables
. generate logconsensus = log10(normconsensus)

. label var logconsensus "log: Size of Winning Coalition"

. tab logconsensus, m

  log: Size |
 of Winning |
  Coalition |      Freq.     Percent        Cum.
------------+-----------------------------------
  -1.431364 |        135        0.17        0.17
   -1.32222 |        193        0.24        0.40
  -1.176091 |        376        0.46        0.87
  -1.079181 |        131        0.16        1.03
  -.9542424 |      1,204        1.49        2.52
  -.8750612 |        176        0.22        2.73
  -.8450981 |        278        0.34        3.08
  -.7781513 |        582        0.72        3.80
  -.7323938 |        210        0.26        4.06
    -.69897 |        831        1.03        5.08
  -.6532125 |        439        0.54        5.62
  -.6232493 |        344        0.42        6.05
    -.60206 |        310        0.38        6.43
  -.5862657 |        260        0.32        6.75
  -.5740313 |        283        0.35        7.10
  -.4771213 |      4,503        5.56       12.66
    -.39794 |        319        0.39       13.05
  -.3899711 |        348        0.43       13.48
  -.3802112 |        356        0.44       13.92
  -.3679768 |        369        0.46       14.38
  -.3521825 |        388        0.48       14.86
  -.3309932 |        904        1.12       15.97
  -.3174204 |        303        0.37       16.35
    -.30103 |        981        1.21       17.56
  -.2808266 |        359        0.44       18.00
  -.2730013 |        285        0.35       18.35
  -.2552725 |      1,159        1.43       19.79
  -.2340833 |        285        0.35       20.14
  -.2218487 |        627        0.77       20.91
   -.208276 |        319        0.39       21.30
  -.2009148 |        263        0.32       21.63
  -.1760912 |      2,444        3.02       24.65
  -.1526101 |        200        0.25       24.89
   -.146128 |        252        0.31       25.20
  -.1346986 |        420        0.52       25.72
  -.1249387 |        162        0.20       25.92
  -.1091445 |        795        0.98       26.90
    -.09691 |        124        0.15       27.06
  -.0917704 |        171        0.21       27.27
  -.0791813 |        538        0.66       27.93
  -.0696359 |         98        0.12       28.05
  -.0621479 |        248        0.31       28.36
  -.0511525 |        135        0.17       28.53
  -.0434657 |         90        0.11       28.64
  -.0377885 |         79        0.10       28.74
  -.0334238 |         62        0.08       28.81
  -.0299632 |         51        0.06       28.88
          0 |     57,611       71.12      100.00
------------+-----------------------------------
      Total |     81,000      100.00

. generate logvthresh = log10(normvthresh)

. label var logvthresh "log: Voting Threshold"

. tab logvthresh

log: Voting |
  Threshold |      Freq.     Percent        Cum.
------------+-----------------------------------
   -1.69897 |      9,000       11.11       11.11
         -1 |      9,000       11.11       22.22
    -.69897 |      9,000       11.11       33.33
  -.5228787 |      9,000       11.11       44.44
    -.39794 |      9,000       11.11       55.56
    -.30103 |      9,000       11.11       66.67
  -.2218487 |      9,000       11.11       77.78
   -.154902 |      9,000       11.11       88.89
    -.09691 |      9,000       11.11      100.00
------------+-----------------------------------
      Total |     81,000      100.00

. 
. 
. * Save data for non-linear quantile regression analysis in R and load results
. *****************************************************************************
. 
. * Save data for model fitting in R
. compress

. saveold "Experiments\Experiment01\cbld-analysis02-fig05.dta", replace
file Experiments\Experiment01\cbld-analysis02-fig05.dta saved

. 
. * Load quantile regression estimation results from R
. use "Experiments\\Experiment01\\cbld-analysis02-fig05-r.dta", clear
(Written by R.              )

. 
.         
. * Generate plot of non-linear affect of voting threshold on winning coalition 
> size
. ******************************************************************************
> ****
. 
. * Generate additional variables for plotting
. generate x = _n/100 in 1/100
(80900 missing values generated)

. generate x100 = x*100/2+50
(80900 missing values generated)

. 
. * Plot median prediction curve and simulated median winning coalition size aga
> inst voting threshold for each membership size
. foreach k of numlist 6 9 12 15 18 21 24 27 30 {         
  2.         * Save median winning coalition size in local for each combination 
> of voting threshold and membership size
.         foreach i of numlist 51 55 60 65 70 75 80 85 90 {
  3.                 qui sum consensus if vthresh == `i' & nostates == `k', d
  4.                 local median_`i' = r(p50)
  5.         }
  6.         * Extract exponent for median
.         qui sum cfit2m if nostates == `k', d
  7.         local bm = r(mean)
  8.         local bms = string(round(`bm', .1))
  9.         * Extract intercept for median
.         qui sum ifit2m if nostates == `k', d
 10.         local am = r(mean)
 11.         local ams = string(round(`am', .01))
 12.         * Extract exponent for lower quartile
.         qui sum cfit2lq if nostates == `k', d
 13.         local blq = r(mean)
 14.         * Extract intercept for lower quartile
.         qui sum ifit2lq if nostates == `k', d
 15.         local alq = r(mean)
 16.         * Extract exponent for upper quartile
.         qui sum cfit2uq if nostates == `k', d
 17.         local buq = r(mean)
 18.         * Extract intercept for upper quartile
.         qui sum ifit2uq if nostates == `k', d
 19.         local auq = r(mean)
 20.         * Generate prediction curve for median
.         generate predm`k' = ((`am' + (1-`am')*(1-(1-x)^`bm'))*100)/2+50
 21.         * Generate prediction curve for lower quartile
.         generate predlq`k' = ((`alq' + (1-`alq')*(1-(1-x)^`blq'))*100)/2+50
 22.         * Generate prediction curve for upper quartile
.         generate preduq`k' = ((`auq' + (1-`auq')*(1-(1-x)^`buq'))*100)/2+50
 23.         replace preduq`k' = 50 if preduq`k' < 50
 24.         * Generate plot
.         twoway (rarea preduq`k' predlq`k' x100, color(gs2)) /*
>                 */ (function y = ((ceil((x/100)*`k'))/`k')*100, lcolor(gs4) ra
> nge(51 100) ylabel(50 60:100)) /*
>                 */ (line predm`k' x100, lcolor(white)) /*
>                 */ (scatteri /*
>                 */ `median_90' 90 /*
>                 */ `median_85' 85 /*
>                 */ `median_80' 80 /*
>                 */ `median_75' 75 /*
>                 */ `median_70' 70 /*
>                 */ `median_65' 65 /*
>                 */ `median_60' 60 /*
>                 */ `median_55' 55 /*
>                 */ `median_51' 51, mcolor(white) msymbol(Oh)) /*
>                 */ , aspectratio(0.9)   /*
>                 */  subtitle("`k'", box bexpand) /*
>                 */ legend(order(3 1 4 2) label(1 "Inter-Quartile Range Fit") l
> abel(2 "Effective Voting Threshold") /*
>                 */ label(3 "Median Regression Fit") label(4 "Observed Conditio
> nal Medians") /*
>                 */ size(vsmall) symxsize(*0.4) symysize(*0.4) col(1) region(lc
> olor(black))) /*
>                 */ saving("Data analysis\Graphs\cbld-analysis02-fig05-`k'", re
> place)
 25. }
(80900 missing values generated)
(80900 missing values generated)
(80900 missing values generated)
(0 real changes made)
(file Data analysis\Graphs\cbld-analysis02-fig05-6.gph saved)
(80900 missing values generated)
(80900 missing values generated)
(80900 missing values generated)
(0 real changes made)
(file Data analysis\Graphs\cbld-analysis02-fig05-9.gph saved)
(80900 missing values generated)
(80900 missing values generated)
(80900 missing values generated)
(0 real changes made)
(file Data analysis\Graphs\cbld-analysis02-fig05-12.gph saved)
(80900 missing values generated)
(80900 missing values generated)
(80900 missing values generated)
(1 real change made)
(file Data analysis\Graphs\cbld-analysis02-fig05-15.gph saved)
(80900 missing values generated)
(80900 missing values generated)
(80900 missing values generated)
(0 real changes made)
(file Data analysis\Graphs\cbld-analysis02-fig05-18.gph saved)
(80900 missing values generated)
(80900 missing values generated)
(80900 missing values generated)
(1 real change made)
(file Data analysis\Graphs\cbld-analysis02-fig05-21.gph saved)
(80900 missing values generated)
(80900 missing values generated)
(80900 missing values generated)
(1 real change made)
(file Data analysis\Graphs\cbld-analysis02-fig05-24.gph saved)
(80900 missing values generated)
(80900 missing values generated)
(80900 missing values generated)
(0 real changes made)
(file Data analysis\Graphs\cbld-analysis02-fig05-27.gph saved)
(80900 missing values generated)
(80900 missing values generated)
(80900 missing values generated)
(1 real change made)
(file Data analysis\Graphs\cbld-analysis02-fig05-30.gph saved)

. 
. * Plot all median prediction curves for comparison
. twoway (line predm6 x100, lcolor(white)  aspectratio(0.9) ylabel(50 60:100) xt
> itle("")) /*
>         */ (line predm9 x100, lcolor(white)) /*
>         */ (line predm12 x100, lcolor(white)) /*
>         */ (line predm15 x100, lcolor(white)) /*
>         */ (line predm18 x100, lcolor(white)) /*
>         */ (line predm21 x100, lcolor(white)) /*
>         */ (line predm24 x100, lcolor(white)) /*
>         */ (line predm27 x100, lcolor(white)) /*
>         */ (line predm30 x100, lcolor(white)) /*
>         */ , legend(off) subtitle("Comparison", box bexpand) /*
>         */ saving("Data analysis\Graphs\cbld-analysis02-fig05", replace)
(file Data analysis\Graphs\cbld-analysis02-fig05.gph saved)

. 
. * Drop redundant variables
. drop x1 x100

. 
. * Combine all generated plots into a single graph
. grc1leg /*
>                 */ "Data analysis\Graphs\cbld-analysis02-fig05-6" /*
>                 */ "Data analysis\Graphs\cbld-analysis02-fig05-9" /*
>                 */ "Data analysis\Graphs\cbld-analysis02-fig05-12" /*
>                 */ "Data analysis\Graphs\cbld-analysis02-fig05-15" /*
>                 */ "Data analysis\Graphs\cbld-analysis02-fig05-18" /*
>                 */ "Data analysis\Graphs\cbld-analysis02-fig05-21" /*
>                 */ "Data analysis\Graphs\cbld-analysis02-fig05-24" /*
>                 */ "Data analysis\Graphs\cbld-analysis02-fig05-27" /*
>                 */ "Data analysis\Graphs\cbld-analysis02-fig05-30" /*
>                 */ "Data analysis\Graphs\cbld-analysis02-fig05" /*
>                 */ , cols(3) imargin(tiny) position(5) ring(0) ysize(10) xsize
> (4) /*
>                 */ name(vteffect, replace) /*
>                 */ l1title("Winning Coalition Size", size(small)) /*
>                 */ b1title("Voting Threshold", size(small) bexpand justificati
> on(left) margin(l=6)) /*
>                 */ legendfrom("Data analysis\Graphs\cbld-analysis02-fig05-6")

.                 
. * Reshape and display graph
. graph display vteffect, xsize(4.3) ysize(5)

. 
. 
. log close
      name:  <unnamed>
       log:  E:\Seagate Sync\VOL\Personal folder\Documents\Research\Past project
> s\cbld\Posted\121020 Website\Data analysis\cbld-analysis02-fig05.log
  log type:  text
 closed on:  21 Oct 2012, 15:42:26
--------------------------------------------------------------------------------
